package club.caihappy.controller;

import club.caihappy.pojo.User;
import club.utils.JsonUtils;
import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by 百岁 on 2021/9/13
 **/
@RestController
public class UserController {
    @RequestMapping("/json1")
    public String test1() throws JsonProcessingException {

        List<User> users = new ArrayList<User>();
        User user1 = new User("蔡明宏1号", 21, "男");
        User user2 = new User("蔡明宏2号", 21, "男");
        User user3 = new User("蔡明宏3号", 21, "男");
        User user4 = new User("蔡明宏4号", 21, "男");
        users.add(user1);
        users.add(user2);
        users.add(user3);
        users.add(user4);

        return JSON.toJSONString(users);
//        return JsonUtils.getJson(users);
    }

    @RequestMapping("/json2")
    public String test2() throws JsonProcessingException {
        Date date = new Date();
        return JsonUtils.getJson(date, "yyyy-mm-dd hh:mm:ss");
    }
}
